home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / keyb / buf160_6.zip / BUF160.ASM next >
Assembly Source File  |  1992-01-29  |  13KB  |  479 lines

  1.     title    BUF160
  2.     page    58,132
  3. ; History:1,1
  4. ; Wed Oct 23 17:08:32 1991
  5. ;
  6. ; v1.6a, 2-29-92, Robert M. Ryan
  7. ; - Added CLI and STI in installation routine. (hgm)
  8. ;
  9. ; v1.6,     2-26-92, Robert M. Ryan
  10. ; - On conditional assembly of PRIVATESTACK, this program will create it's
  11. ;   own stack.    This was implemented due to problems on some older PCs.
  12. ; - Refine checking of segment boundries, based upon recommendation by
  13. ;   Harry McGavran (hgm@moki.lanl.gov)
  14. ; - Added missing a LES before stuffing data into driver header. (also hgm)
  15. ; - Eliminated unnecessary structures and generally cleaned up code.
  16. ; - Changed name to BUF160, rather than BUF160_4, BUF160_5, etc.
  17. ;
  18. ; v1.5 10-23-91 Robert M. Ryan
  19. ; - using PUSHA and SHL AX,4 on conditional assembly for 286
  20. ; - changed the default buffer status to have TRANSFER enabled, so that
  21. ;   keys pressed during initialization are preserved.
  22. ; - changed case of es and ds to be like the rest of the registers
  23. ; - added initialization of BX so Cmd_Init would work
  24. ; - slightly modified initialization message
  25. ;
  26. ; Rob Ryan, Brown University
  27. ; Robert_Ryan@brown.edu or 70324.227@CompuServe.Com
  28. ;
  29. ; v1.4 09-26-88 Toad Hall Tweak
  30. ; - Donno WHY all the public mess.  Leaving it, tho.
  31. ; - Donno why author commented out the buffer transfer code.
  32. ;   I guess, since we're loading as a driver right at system startup,
  33. ;   there shouldn't BE anything in the old keyboard buffer.
  34. ;   Driver works fine with TRANSFER enabled (1), but donno what good it
  35. ;   does.  Therefore leaving the default (and compiled driver) OFF (0).
  36. ; - Changed case: constants UPPERCASE, procedures mixed Upper_Lower,
  37. ;   variables remain lowercase.     (Helps to keep my head straight.)
  38. ; - Added some comments.
  39. ; - Moved Force inline (since only called once)
  40. ; - Using string commands in Transfer_Buffer (lodsw, stosw)
  41. ; - Just below Transfer_Done, recoded to use AX when stuffing words
  42. ;   into variables (faster than old code using CX).
  43. ;
  44. ; David Kirschbaum
  45. ; Toad Hall
  46. ; kirsch@braggvax.ARPA
  47. ;
  48. ; 09-21-87 09:31:17 v1.3, fix buf in Force().
  49. ; 09-16-87 16:07:46 v1.2, added publics
  50. ; 09-16-87 16:01:41 v1.1, comment out buffer transfer code with equate
  51. ;
  52. ; DJ Delorie
  53. ;
  54. ;
  55. ; To compile:
  56. ;
  57. ;    MICROSOFT ASSEMBLER            TURBO ASSEMBLER
  58. ;    -------------------            ---------------
  59. ;    masm BUF160;                tasm BUF160
  60. ;    link BUF160;                tlink BUF160
  61. ;    exe2bin BUF160.exe BUF160.sys        exe2bin BUF160.exe BUF160.sys
  62. ;
  63. ; To install, insert the following line in your config.sys:
  64. ;
  65. ;    DEVICE=<path>BUF160.SYS
  66. ;
  67. ; where "<path>" is the path of the directory containing the device driver
  68. ; (e.g., C:\BIN\).
  69.  
  70.  
  71. ;*****************************************************************************
  72. ; Compilation flags
  73. ;*****************************************************************************
  74.  
  75. TRANSFER    equ    1    ;Enables keyboard buffer transfer    v1.4
  76.                 ;  procedure if enabled (1)        v1.4
  77. USE286        equ    0    ;Should we use 286 (and later)        v1.5
  78.                 ;  CPU specific instructions?        v1.5
  79. PRIVATESTACK    equ    1    ;Use own stack?                v1.6
  80.  
  81. PROGNAME    equ    'BUF160'
  82. VERSION        equ    'v1.6a, 29 January 1992'
  83.  
  84. ;*****************************************************************************
  85. ; General equates
  86. ;*****************************************************************************
  87.  
  88. BUFSIZE    equ    160        ;What is the size of the keyboard buffer
  89. STACKSZ    equ    100h        ;What is the size of the private buffer
  90. SUCCESS    equ    0100h
  91. ERROR    equ    8100h
  92. BUSY    equ    0300h
  93. CR    equ    13        ;Carriage Return
  94. LF    equ    10        ;Line Feed
  95. TERM    equ    '$'        ;DOS printing terminator character
  96.  
  97. ;*****************************************************************************
  98. ; Data structures
  99. ;*****************************************************************************
  100.  
  101. dqq    struc
  102. ofs    dw    ?
  103. segw    dw    ?        ;changed from 'seg' to keep MASM 5.0 happy v1.4
  104. dqq    ends
  105.  
  106. rqq    struc            ;Request header structure
  107. len    db    ?        ;length of request block (bytes)
  108. unit    db    ?        ;unit #
  109. code    db    ?        ;driver command code
  110. status    dw    ?        ;status return
  111. q1    dd    ?        ;8 reserved bytes
  112. q2    dd    ?
  113. mdesc    db    ?        ;donno
  114. trans    dd    ?
  115. count    dw    ?
  116. rqq    ends
  117.  
  118. ;*****************************************************************************
  119. ; Pointers to BIOS data segment, v1.4
  120. ;*****************************************************************************
  121.  
  122. BIOS_DATA_SEG    equ 40H        ;MASM had prob using BIOS_DATA in calculations,
  123.                 ;   so this typeless constant introduced.  v1.6
  124.  
  125. BIOS_DATA    SEGMENT AT BIOS_DATA_SEG
  126.     org    1AH
  127. BUFFER_GET    dw    ?    ;org    1ah
  128. BUFFER_PUT    dw    ?    ;org    1ch
  129.     org    80H
  130. BUFFER_START    dw    ?    ;org    80h
  131. BUFFER_END    dw    ?    ;org    82h
  132. BIOS_DATA    ENDS
  133.  
  134.  
  135. ;*****************************************************************************
  136. ; The actual program
  137. ;*****************************************************************************
  138.  
  139. Cseg    segment    byte
  140.     assume    cs:Cseg,ds:Cseg,es:Cseg,ss:Cseg
  141.     org    0            ; no offset, it's a .SYS file
  142. start    equ    $            ; define start=CS:0000
  143.  
  144. IF USE286                ;                v1.5
  145.     .286
  146.     %OUT Compiling 286 code ...
  147. ELSE
  148.     %OUT Compiling generic 8086 code ...
  149. ENDIF
  150. IF PRIVATESTACK
  151.     %OUT Using private stack ...
  152. ELSE
  153.     %OUT Not using private stack ...
  154. ENDIF
  155. IF TRANSFER
  156.     %OUT Including keyboard transfer code ...
  157. ELSE
  158.     %OUT Not including keyboard transfer code ...
  159. ENDIF
  160.  
  161.     public    header
  162. header    label    near
  163.     dd    -1            ;pointer to next device
  164.     dw    8000h            ;type device
  165.     dw    Strat            ;strategy entry point
  166.     dw    Intr            ;interrupt entry point
  167.     db    'KBUFFER '        ;device name
  168.  
  169.     public    req
  170. req    dd    ?            ;store request header vector here
  171.  
  172.     public    queue_start,queue_end
  173. queue_start dw    BUFSIZE dup (0)        ;our expanded keyboard buffer
  174. queue_end   equ    $ - start        ;calculate offset as typeless constant
  175.  
  176. IF PRIVATESTACK                ;                v1.6
  177.  
  178. stack_end    db   STACKSZ dup (0)    ;use our own private data stack
  179. stack_start    equ  $
  180. oldss    dw    0
  181. oldsp    dw    0
  182. oldax    dw    0
  183.  
  184. ENDIF
  185.  
  186. ;*****************************************************************************
  187. ; Strategy procedure
  188. ;    Save the pointer to the request header for Intr in the req area.
  189. ;    Enters with pointer in es:bx
  190. ;*****************************************************************************
  191.  
  192.     public    Strat
  193. Strat    proc    far
  194.     mov    cs:[req].ofs,bx
  195.     mov    cs:[req].segw,es    ;                v1.4
  196.     ret
  197. Strat    endp
  198.  
  199. ;*****************************************************************************
  200. ; The main interrupt (driver)
  201. ;    This is the actual driver.  Processes the command contained in the
  202. ;    request header.     (Remember, req points to the request header.)
  203. ;*****************************************************************************
  204.  
  205.     public    Intr
  206.     ASSUME    ds:Cseg, es:NOTHING    ;                v1.4
  207. Intr    proc    far
  208.  
  209. IF PRIVATESTACK                ;If using private stack, process
  210.     mov    cs:oldax, ax        ;                v1.6
  211.     cli                ; turn ints off
  212.     mov    ax, ss
  213.     mov    cs:oldss, ax
  214.     mov    cs:oldsp, sp
  215.     mov    sp, offset stack_start
  216.     mov    ax, cs
  217.     mov    ss, ax
  218.     sti                ; turn ints back on
  219.     mov    ax, cs:oldax
  220. ENDIF
  221.  
  222.     push    ds            ;save everything in sight
  223.     push    es
  224. IF USE286
  225.     pusha                ;                v1.5
  226. ELSE
  227.     push    ax
  228.     push    bx
  229.     push    cx
  230.     push    dx
  231.     push    di
  232.     push    si
  233. ENDIF
  234.  
  235.     mov    ax,cs
  236.     mov    ds,ax            ;DS=code segment
  237.  
  238.     les    bx,req            ;point to request hdr        v1.4a
  239.     mov    si,offset cmd_table    ;our function table
  240.     mov    cl,es:[bx].code        ;get command
  241.     xor    ch,ch            ;clear msb            v1.4
  242.     shl    cx,1            ;*2 for word addresses
  243.     add    si,cx            ;add to table base
  244.  
  245.     call    word ptr [si]        ;call our function        v1.4a
  246.     les    bx,cs:req        ;get back request hdr vector
  247.     mov    es:[bx].status,ax    ;return status
  248. IF USE286
  249.     popa                ;                v1.5
  250. ELSE
  251.     pop    si            ;clean everything up
  252.     pop    di
  253.     pop    dx
  254.     pop    cx
  255.     pop    bx
  256.     pop    ax
  257. ENDIF
  258.     pop    es
  259.     pop    ds
  260.  
  261. IF PRIVATESTACK
  262.     mov    ax, cs:oldss        ;                v1.6
  263.     cli                ; turn ints off
  264.     mov    ss, ax
  265.     mov    sp, cs:oldsp
  266.     mov    ax, cs:oldax
  267.     sti                ; turn ints on
  268. ENDIF
  269.  
  270.     ret
  271.  
  272.     public    cmd_table
  273. cmd_table:                ;command routing table
  274.     dw    Cmd_Init        ;0=initialization (we do that)
  275.     dw    Cmd_None        ;1=media check (always SUCCESS)
  276.     dw    Cmd_None        ;2=build BIOS param block (ditto)
  277.     dw    Cmd_None        ;3=IO control input (ditto)
  278.     dw    Cmd_None        ;4=input from device (ditto)
  279.     dw    Cmd_None        ;5=nondest input no-wait (ditto)
  280.     dw    Cmd_None        ;6=input status (ditto)
  281.     dw    Cmd_None        ;7=flush input